package br.com.ps.bombertournament;

import br.com.ps.bombertournament.game.Scene;
import br.com.ps.bombertournament.game.scene.BattleScene;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class SceneManager implements ApplicationListener {

	private Scene scene;

	private SpriteBatch spriteBatch;
	
	public SceneManager(Scene scene) {
		this.scene = scene;
	}
	
	public SceneManager() {
		// TODO Change to the start scene here
		this(new BattleScene("data/scene/bomber_zone/bomber_zone.json"));
	}

	@Override
	public void create() {
		this.scene.create(this);
		
		spriteBatch = new SpriteBatch();
	}

	@Override
	public void resume() {
		scene.resume();
	}

	public void resize(int width, int height) {
		scene.resize(width, height);
	}

	@Override
	public void pause() {
		scene.pause();
	}

	@Override
	public void dispose() {
		scene.dispose();
	}

	@Override
	public void render() {
		GL10 gl = Gdx.graphics.getGL10();
		
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		scene.update(Gdx.graphics.getDeltaTime());

		spriteBatch.begin();
		
		scene.render(spriteBatch);
		
		spriteBatch.end();
	}

	public void setScene(Scene scene) {
		this.scene.removed();
		this.scene = scene;
		
		scene.create(this);
	}
}